/* $Id: stack.h 13 2006-12-14 21:07:45Z judas $ */

#ifndef NIH_STACK_H
#define NIH_STACK_H 1

#include <nih/cdefs.h>

BEGIN_C_DECLS

#include <nih/list.h>
#include <nih/types.h>

#include <stdlib.h>
#include <sys/types.h>

struct nih_stack {
	struct nih_llist *list;
	ssize_t maxlen;
	size_t len;
	void *udata;
};

extern struct nih_stack *nih_screate_len(ssize_t maxlen);

extern inline struct nih_stack *nih_screate()
{
        return nih_screate_len(-1);
}

extern int nih_spush(struct nih_stack *stack, const void *value);

extern int nih_spop(struct nih_stack *stack, void **value);

extern int nih_sdestroy_deep(struct nih_stack *stack, nih_free_fnc *free_fnc);

extern inline int nih_sdestroy(struct nih_stack *stack)
{
        return nih_sdestroy_deep(stack, NULL);
}

END_C_DECLS

#endif /* NIH_STACK_H */

